#include <vector>
using namespace std;

/*
gemm
    A: [M x K]
    B: [K x N]
    C: [M x N]
*/
void gemm(int M, int N, int K, float *A, float *B, float *C){
    int _i, _j, _k;
    for(_i = 0; _i < M; ++_i){
        for(_k = 0; _k < K; ++_k){
            register float A_PART = A[_i * K + _k];
            for(_j = 0; _j < N; ++_j){
                C[_i * N + _j] += A_PART*B[_k * N + _j];
            }
        }
    }
}

/*
vector.at degrades the performance very much
vector [] has a slight degradation
*/
void gemm(int M, int N, int K, vector<float>& A, vector<float>& B, vector<float>& C){
    int _i, _j, _k;
    for(_i = 0; _i < M; ++_i){
        for(_k = 0; _k < K; ++_k){
            register float A_PART = A[_i * K + _k];
            for(_j = 0; _j < N; ++_j){
                C[_i * N + _j] += A_PART*B[_k * N + _j];
            }
        }
    }
}